package com.example.controleautomovel.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.controleautomovel.R;
import com.example.controleautomovel.pojo.Automovel;

public class AdaptadorListaAutomovel extends BaseAdapter{
	
	Context ctx;
	ArrayList<Automovel> lista;
	
	public AdaptadorListaAutomovel(Context ctx, ArrayList<Automovel> lista) {
		this.ctx = ctx;
		this.lista = lista;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lista.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return lista.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(R.layout.item_lista_automoveis, null);
		
		TextView txtNomeAutomovel = (TextView) convertView.findViewById(R.id.txtNomeAutomovel);
		TextView txtMarcaAutomovel = (TextView) convertView.findViewById(R.id.txtMarcaAutomovel);
		TextView txtModeloAutomovel = (TextView) convertView.findViewById(R.id.txtModeloAutomovel);
		TextView txtAnoAutomovel = (TextView) convertView.findViewById(R.id.txtAno);
		TextView txtIdAutomovel = (TextView) convertView.findViewById(R.id.txtIdAutomovel);
		ImageView imageCarro = (ImageView) convertView.findViewById(R.id.imageCarro);
		
		Automovel c = lista.get(position);
		
		txtNomeAutomovel.setText(c.getNome());
		txtMarcaAutomovel.setText(c.getMarca());
		txtModeloAutomovel.setText(c.getModelo());
		txtAnoAutomovel.setText(c.getAno());
		
		
//		txtIdAutomovel.setText(c.getId());
		
		return convertView;
	}
	
}
